
cd D:\Dropbox\book_welfare\replication 

************************************************
* Effects on entire distribution - Bookstat 
************************************************



use data\bookstat_gender_pyear_genre_asin.dta, clear
	collapse (sum) males=N_male name_present=N_name total, by(pyear genre)
	tempfile number
	save `number'
	
use  data\bookstat_sales_gender_pyear_genre_decile_asin.dta, clear 
		collapse (sum) q qm=q_male qname=q_name, by(pyear year genre decile)

		merge m:1 pyear genre using `number'

		* of those with identification
		gen rv_old =  1 - males/name_present 	
		gen sf_old = 1 - qm/qname 
				

		* known women over total (conservative )
		gen rv = (name_present - males)/total 
		gen sf = (qname - qm)/q 

		keep if year>=2018 & year<=2021 
		keep if pyear>=1960 & pyear<=2021 		
		keep if pyear>=1960

		label var sf "share of vintage sales"
		label var rv "female-authored share of new products"


*******************

		egen gno=group(genre)
		reghdfe sf i.decile#c.rv [weight=q], absorb(decile year gno pyear) 


		parmest, norestore 

			split parm, parse("b.decile" ".decile")
			
			gen decile = real(parm1)+1 
			
			twoway (scatter estimate decile ) (rcap max95 min95 decile) if decile~=. & decile>=1, scheme(lean2) ///
			ytitle(female sales share coefficient) xtitle(decile of sales distribution) legend(off) yline(1)
			
			graph export "latex_text\figures\coeff_by_sales_decile_at_asin.pdf", as(pdf) name("Graph") replace 
	
	
	
************************************************
* Effects on entire distribution - Goodreads 
************************************************


use  data\books_year.dta, clear  


		keep if year>=2007 & year<=2016
		keep if pubyr >=1960 & pubyr<=2016 
		drop if fbookp==. 
		* replace fbook=0 if fbook==.
		collapse (count) n=q , by(pubyr fbookp genre1 )
		tempfile gr 
		save `gr'



use  data\books_year.dta, clear  


		keep if year>=2007 & year<=2016
		keep if pubyr >=1960 & pubyr<=2016 
	
		replace fbookp=0 if fbookp==.
		* replace fbook=0 if fbook==.

		xtile decile = q, nq(10)
		collapse (sum) qf qm q , by(year pubyr fbookp genre1 decile )

		merge m:1 pubyr fbookp genre1 using `gr'

		egen gno=group(genre1)


		egen Qv = sum(q), by(genre1 year pubyr decile)
		gen sv=q/Qv

		egen Nv = sum(n), by(genre1 year pubyr decile)
		gen rv = n/Nv

		egen QFv = sum(qf), by(genre1 year pubyr decile)
		gen sfv=qf/QFv
		egen QMv = sum(qm), by(genre1 year pubyr decile)
		gen smv=qm/QMv


		egen N=sum(n), by(pubyr) 
			
		label var sv "female-authored share of consumption"
		label var rv "female-authored share of new products"
		label var sfv "fem-auth shr of female cons"
		label var smv "fem-auth shr of male cons"

		gen gy = gno*10000 + year 

		reghdfe sv i.decile#c.rv [weight=Qv], nocon absorb(decile year gno pubyr) 




	parmest, norestore 

		split parm, parse("b.decile" ".decile")

		gen decile = real(parm1) 

		twoway (scatter estimate decile ) (rcap max95 min95 decile) if decile~=. & decile>=1, scheme(lean2) ///
		ytitle(female sales share coefficient) xtitle(decile of sales distribution) legend(off) yline(1)
	
	graph export "latex_text\figures\coeff_by_sales_decile_at_gr.pdf", as(pdf) name("Graph") replace 
	
